package com.yanqu.road.dao.impl.beautyescort;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.beautyescort.EscortBeautyEventBossInfo;
import com.yanqu.road.entity.beautyescort.EscortClientInfo;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class BeautyEscortConfigDaoImpl extends TempDao {

    private static String getEscortClientInfoSql = "select * from `t_p_escort_client` ORDER BY `id` ASC";
    public Map<Integer, EscortClientInfo> getEscortClientInfoMap() {
        Map<Integer, EscortClientInfo> result = new ConcurrentHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getConfigDb());
            call = getDb().getConnection().prepareCall(getEscortClientInfoSql);
            rs = call.executeQuery();
            while (rs.next()) {
                EscortClientInfo data = new EscortClientInfo();
                data.setId(rs.getInt("id"));
                data.setWeight(rs.getInt("weight"));
                result.put(data.getId(), data);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return result;
    }

    private static String getEscortBeautyEventBossInfoSql = "select * from `t_p_escort_event_boss` ORDER BY `id` ASC";
    public Map<Integer, EscortBeautyEventBossInfo> getEscortBeautyEventBossInfoMap() {
        Map<Integer, EscortBeautyEventBossInfo> result = new ConcurrentHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getConfigDb());
            call = getDb().getConnection().prepareCall(getEscortBeautyEventBossInfoSql);
            rs = call.executeQuery();
            while (rs.next()) {
                EscortBeautyEventBossInfo data = new EscortBeautyEventBossInfo();
                data.setId(rs.getInt("id"));
                data.setHp(rs.getLong("hp"));
                data.setRewards(rs.getString("rewards"));
                data.setBaseRewards(rs.getString("baseRewards"));
                data.setWeight(rs.getInt("weight"));
                data.setUnionLevel(rs.getInt("unionLevel"));
                result.put(data.getId(), data);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return result;
    }

}
